package com.xls.box2023.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lzz.bottomencapsulation.consts.Consts;
import com.lzz.bottomencapsulation.holder.MvpRVViewHolder;
import com.lzz.bottomencapsulation.utils.LUtils;
import com.lzz.bottomencapsulation.utils.TimeUtil;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.xls.box2023.Consts.StateConsts;
import com.xls.box2023.R;
import com.xls.box2023.customcontrol.RoundedImageView;
import com.xls.box2023.entity.JiFenMingXiEntity;
import com.xls.box2023.jifen.duihuanjibi.DuiHuanJiBiActivity;
import com.xls.box2023.jinbi.jifenduihuanjilu.JiFenDuiHuanJiLuActivity;
import com.xls.box2023.tuiguangyouxi.TuiGuangYouXiActivity;

public class JiFenMingXiViewHolder extends MvpRVViewHolder<JiFenMingXiEntity> {
    private RoundedImageView youxi_icon;
    private TextView youxi_name;
    private TextView youxi_org;
    private TextView youxi_shouyi_jiri;
    private TextView youxi_shouyi_jiri_num;
    private TextView youxi_shouyi_yue;
    private TextView youxi_shouyi_yue_num;
    private RelativeLayout item_youxi;
    private TextView tv_line;
    private TextView jifenmingxi_shouyi_title;
    private TextView jifenmingxi_jinrishouyi_title;
    private TextView jifenmingxi_zongshouyi_title;
    private TextView jifenmingxi_yue_title;
    private TextView jifenmingxi_xiaohao_title;
    private TextView jifenmingxi_jinrishouyi_num;
    private TextView jifenmingxi_zongshouyi_num;
    private TextView jifenmingxi_yue_num;
    private TextView jifenmingxi_xiaohao_num;
    private TextView jifenmingxi_jinrishouyi_mingxi;
    private TextView jifenmingxi_zongshouyi_mingxi;
    private TextView jifenmingxi_xiaohao_mingxi;
    private TextView jifenmingxi_shouyi_duihuan;
    private RelativeLayout jifen_shouyi;
    private TextView tv_line2;
    private TextView tuiguangjifenmingxi_shouyi_title;
    private TextView tuiguangjifenmingxi_jinrishouyi_title;
    private TextView tuiguangjifenmingxi_jinrishouyi_num;
    private TextView tuiguangjifenmingxi_jinrishouyi_mingxi;
    private TextView tuiguangjifenmingxi_zongshouyi_title;
    private TextView tuiguangjifenmingxi_zongshouyi_num;
    private TextView tuiguangjifenmingxi_zongshouyi_mingxi;
    private TextView tuiguangjifenmingxi_yue_title;
    private TextView tuiguangjifenmingxi_yue_num;
    private TextView tuiguangjifenmingxi_shouyi_duihuan;
    private TextView tuiguangjifenmingxi_xiaohao_title;
    private TextView tuiguangjifenmingxi_xiaohao_num;
    private TextView tuiguangjifenmingxi_xiaohao_mingxi;
    private RelativeLayout jifen_tuiguangshouyi;

    public JiFenMingXiViewHolder(Context context, ViewGroup p) {
        super(R.layout.item_jifenmingxi, context, p);
    }

    @Override
    public void initView() {

        youxi_icon = itemView.findViewById(R.id.youxi_icon);
        youxi_name = itemView.findViewById(R.id.youxi_name);
        youxi_org = itemView.findViewById(R.id.youxi_org);
        youxi_shouyi_jiri = itemView.findViewById(R.id.youxi_shouyi_jiri);
        youxi_shouyi_jiri_num = itemView.findViewById(R.id.youxi_shouyi_jiri_num);
        youxi_shouyi_yue = itemView.findViewById(R.id.youxi_shouyi_yue);
        youxi_shouyi_yue_num = itemView.findViewById(R.id.youxi_shouyi_yue_num);
        item_youxi = itemView.findViewById(R.id.item_youxi);
        tv_line = itemView.findViewById(R.id.tv_line);
        jifenmingxi_shouyi_title = itemView.findViewById(R.id.jifenmingxi_shouyi_title);
        jifenmingxi_jinrishouyi_title = itemView.findViewById(R.id.jifenmingxi_jinrishouyi_title);
        jifenmingxi_zongshouyi_title = itemView.findViewById(R.id.jifenmingxi_zongshouyi_title);
        jifenmingxi_yue_title = itemView.findViewById(R.id.jifenmingxi_yue_title);
        jifenmingxi_xiaohao_title = itemView.findViewById(R.id.jifenmingxi_xiaohao_title);
        jifenmingxi_jinrishouyi_num = itemView.findViewById(R.id.jifenmingxi_jinrishouyi_num);
        jifenmingxi_zongshouyi_num = itemView.findViewById(R.id.jifenmingxi_zongshouyi_num);
        jifenmingxi_yue_num = itemView.findViewById(R.id.jifenmingxi_yue_num);
        jifenmingxi_xiaohao_num = itemView.findViewById(R.id.jifenmingxi_xiaohao_num);
        jifenmingxi_jinrishouyi_mingxi = itemView.findViewById(R.id.jifenmingxi_jinrishouyi_mingxi);
        jifenmingxi_zongshouyi_mingxi = itemView.findViewById(R.id.jifenmingxi_zongshouyi_mingxi);
        jifenmingxi_xiaohao_mingxi = itemView.findViewById(R.id.jifenmingxi_xiaohao_mingxi);
        jifenmingxi_shouyi_duihuan = itemView.findViewById(R.id.jifenmingxi_shouyi_duihuan);
        jifenmingxi_shouyi_duihuan.setOnClickListener(this);
        jifenmingxi_jinrishouyi_mingxi.setOnClickListener(this);
        jifenmingxi_zongshouyi_mingxi.setOnClickListener(this);
        jifenmingxi_xiaohao_mingxi.setOnClickListener(this);



//        游戏图标
        if (!TextUtils.isEmpty(viewData.getPicture())){
            DisplayImageOptions options = new DisplayImageOptions.Builder()
                    .cacheInMemory(false)// 设置下载的图片是否缓存在内存中
                    .cacheOnDisk(true)// 设置下载的图片是否缓存在SD卡中
                    .build();
            ImageLoader.getInstance().displayImage(viewData.getPicture(),youxi_icon, options);
        }

        if (!TextUtils.isEmpty(viewData.getAppName())){
            youxi_name.setText(viewData.getAppName());
        }

        if (!TextUtils.isEmpty(viewData.getTenantName())){
            youxi_org.setText(viewData.getTenantName());
        }

        youxi_shouyi_jiri_num.setText((Long.parseLong(viewData.getScoreToday())+Long.parseLong(viewData.getRefferScoreToday()))/ Consts.JiFenDanWei+" 元宝");
        youxi_shouyi_yue_num.setText((viewData.getFxScoreStr())+" 元宝");


        jifenmingxi_jinrishouyi_num.setText(viewData.getScoreTodayStr()+" 元宝");
        jifenmingxi_zongshouyi_num.setText(viewData.getScoreTotalStr()+" 元宝");
        jifenmingxi_yue_num.setText(viewData.getScoreStr()+" 元宝");
        Long ExchangeScoreTotal= (long) (Double.parseDouble(viewData.getScoreTotal())-Double.parseDouble(viewData.getScore()));
        jifenmingxi_xiaohao_num.setText(ExchangeScoreTotal/Consts.JiFenDanWei+" 元宝");
        jifen_shouyi = itemView.findViewById(R.id.jifen_shouyi);
        tv_line2 = itemView.findViewById(R.id.tv_line2);
        tuiguangjifenmingxi_shouyi_title = itemView.findViewById(R.id.tuiguangjifenmingxi_shouyi_title);
        tuiguangjifenmingxi_jinrishouyi_title = itemView.findViewById(R.id.tuiguangjifenmingxi_jinrishouyi_title);
        tuiguangjifenmingxi_jinrishouyi_num = itemView.findViewById(R.id.tuiguangjifenmingxi_jinrishouyi_num);
        tuiguangjifenmingxi_jinrishouyi_mingxi = itemView.findViewById(R.id.tuiguangjifenmingxi_jinrishouyi_mingxi);
        tuiguangjifenmingxi_zongshouyi_title = itemView.findViewById(R.id.tuiguangjifenmingxi_zongshouyi_title);
        tuiguangjifenmingxi_zongshouyi_num = itemView.findViewById(R.id.tuiguangjifenmingxi_zongshouyi_num);
        tuiguangjifenmingxi_zongshouyi_mingxi = itemView.findViewById(R.id.tuiguangjifenmingxi_zongshouyi_mingxi);
        tuiguangjifenmingxi_yue_title = itemView.findViewById(R.id.tuiguangjifenmingxi_yue_title);
        tuiguangjifenmingxi_yue_num = itemView.findViewById(R.id.tuiguangjifenmingxi_yue_num);
        tuiguangjifenmingxi_shouyi_duihuan = itemView.findViewById(R.id.tuiguangjifenmingxi_shouyi_duihuan);
        tuiguangjifenmingxi_xiaohao_title = itemView.findViewById(R.id.tuiguangjifenmingxi_xiaohao_title);
        tuiguangjifenmingxi_xiaohao_num = itemView.findViewById(R.id.tuiguangjifenmingxi_xiaohao_num);
        tuiguangjifenmingxi_xiaohao_mingxi = itemView.findViewById(R.id.tuiguangjifenmingxi_xiaohao_mingxi);
        jifen_tuiguangshouyi = itemView.findViewById(R.id.jifen_tuiguangshouyi);
        Long ExchangeRefferScoreTotal= (long) (Double.parseDouble(viewData.getRefferScoreTotal())-Double.parseDouble(viewData.getRefferScore()));
        tuiguangjifenmingxi_jinrishouyi_num.setText(viewData.getRefferScoreTodayStr()+" 元宝");
        tuiguangjifenmingxi_zongshouyi_num.setText(viewData.getRefferScoreTotalStr()+" 元宝");
        tuiguangjifenmingxi_yue_num.setText(viewData.getRefferScoreStr()+" 元宝");
        tuiguangjifenmingxi_xiaohao_num.setText(ExchangeRefferScoreTotal/Consts.JiFenDanWei+" 元宝");

        tuiguangjifenmingxi_shouyi_duihuan.setOnClickListener(this);
        tuiguangjifenmingxi_jinrishouyi_mingxi.setOnClickListener(this);
        tuiguangjifenmingxi_zongshouyi_mingxi.setOnClickListener(this);
        tuiguangjifenmingxi_xiaohao_mingxi.setOnClickListener(this);

        LUtils.e("游戏",viewData.toString());

        if (viewData.getAllowWithdrawBox()==1){
            jifenmingxi_shouyi_duihuan.setVisibility(View.VISIBLE);
        }else {
            jifenmingxi_shouyi_duihuan.setVisibility(View.GONE);
        }

        if (viewData.getAllowPromoteBox()==1){
            tuiguangjifenmingxi_shouyi_duihuan.setVisibility(View.VISIBLE);
        }else {
            tuiguangjifenmingxi_shouyi_duihuan.setVisibility(View.GONE);
        }
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.jifenmingxi_shouyi_duihuan) {
            DuiHuanJiBiActivity.startActivity(context,viewData.getAppId(),viewData.getPackageName(), StateConsts.TiXianType.ShouYi);
        } else if (id == R.id.jifenmingxi_jinrishouyi_mingxi) {
        } else if (id == R.id.jifenmingxi_zongshouyi_mingxi) {
        } else if (id == R.id.jifenmingxi_xiaohao_mingxi) {
            JiFenDuiHuanJiLuActivity.startActivity(context,viewData.getAppId(),StateConsts.TiXianType.ShouYi);
        }else if (id == R.id.tuiguangjifenmingxi_shouyi_duihuan){
            DuiHuanJiBiActivity.startActivity(context,viewData.getAppId(),viewData.getPackageName(), StateConsts.TiXianType.TuiGuang);
        }else if (id == R.id.tuiguangjifenmingxi_jinrishouyi_mingxi){
            TuiGuangYouXiActivity.start(context,viewData.getAppId(),viewData.getPackageName(),TimeUtil.getText(TimeUtil.yMd,TimeUtil.getTimeMliiis()),TimeUtil.getText(TimeUtil.yMd,TimeUtil.getTimeMliiis()),viewData);
        }else if (id == R.id.tuiguangjifenmingxi_zongshouyi_mingxi){
            TuiGuangYouXiActivity.start(context,viewData.getAppId(),viewData.getPackageName(),"2023-10-01", TimeUtil.getText(TimeUtil.yMd,TimeUtil.getTimeMliiis()),viewData);
        }else if (id == R.id.tuiguangjifenmingxi_xiaohao_mingxi){
            JiFenDuiHuanJiLuActivity.startActivity(context,viewData.getAppId(),StateConsts.TiXianType.TuiGuang);
        }
    }
}
